package com.mycompany.myapp.repository;

import com.mycompany.myapp.domain.Commodity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * Spring Data  repository for the Commodity entity.
 */
@SuppressWarnings("unused")
@Repository
public interface CommodityRepository extends JpaRepository<Commodity, Long> {

    @Query("Select cd from Commodity cd where cd.fashion = 1 or cd.quality = 1 and cd.status = '1'")
    List<Commodity> findCommodityByFashionAndQuality();

    @Query("select cd from Commodity cd where cd.status = '1' order by cd.createTime desc" )
    List<Commodity> findTop9ByOrderByCreateTimeDesc(Pageable pageable);

    @Query("select cd from Commodity cd where cname like concat('%',?1,'%') or model like concat('%',?1,'%') and cd.status = '1'")
    Commodity findCommodityByName(String name);

    @Query("select cd from Commodity cd where id = ?1")
    Commodity findCommodityById(Long id);

    @Query("select cd from Commodity cd where model like concat('%',?1,'%') and cd.status = '1' ")
    List<Commodity> findCommodityByType(String type);

    @Query("select cd from Commodity cd where cd.cname like concat('%',?1,'%') and cd.status = '1'")
    Page<Commodity> findByParams(String cname, Pageable pageable);
}
